Skip to content

Add Vulkan GPU context probe (Issue GPU-01 #9) behind CTHREADS_GPU. - #19

Merged
K-T0BIAS merged 1 commit into
4-native-gpu-support-cthreads-for-vulkanspir-vfrom
9-gpu-01-vulkan-context-in-_ext
Sep 5, 2026
Merged

Add Vulkan GPU context probe (Issue GPU-01 #9) behind CTHREADS_GPU.#19
K-T0BIAS merged 1 commit into
4-native-gpu-support-cthreads-for-vulkanspir-vfrom
9-gpu-01-vulkan-context-in-_ext

Conversation

@K-T0BIAS

@K-T0BIAS K-T0BIAS commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Summary

Closes GPU Issue 1: optional Vulkan context in _ext so we can detect a compute device without linking vulkan-1 (loader is LoadLibrary / dlopen at runtime). Default builds stay CPU-only (CTHREADS_GPU=OFF).

CMake / build

  • option(CTHREADS_GPU OFF); when ON: find_package(Vulkan), compile GPU sources, CTHREADS_WITH_GPU=1, Vulkan headers only (no Vulkan::Vulkan link)
  • Enable via CMAKE_ARGS=-DCTHREADS_GPU=ON (cmd/PowerShell) or --config-settings=cmake.define.CTHREADS_GPU=ON; wipe build/ when toggling

C++ runtime (src/cthreads/cpp/gpu/)

  • Process-wide context: open loader -> vkCreateInstance -> pick compute queue (prefer discrete) -> logical device
  • Public API: init / shutdown / available / device_name (mutex + double-checked init; failed init cleans up)

Bindings

  • gpu_module.hpp / gpu_module.cpp -> cthreads._ext.gpu
  • Wired from module.cpp under #ifdef CTHREADS_WITH_GPU

Python

  • cthreads.gpu: soft-import _ext.gpu; available / device_name / init / shutdown
  • errors.py: CThreadsGPUError + mapped types (VulkanNotBuiltError, VulkanLoaderNotFound, VulkanNoDevice, VulkanInitFailed, …)
  • frontend/Gpu/ stubs for later @Gpu work (not functional yet)

Tests

  • tests/unit/test_gpu_context.py: error mapping, not-built soft path, fake _ext.gpu; live Vulkan tests skip when not built or no device

Other

  • .clangd for Vulkan/project includes (local IntelliSense)
  • .gitignore: ignore *.gif demo artifacts

Test plan

  • CPU-only: pip install -e .; from cthreads import gpu; gpu.available() is False; import does not crash
  • GPU build (VS Dev Cmd / venv): set CMAKE_ARGS=-DCTHREADS_GPU=ON + pip install -e . -v; log shows cthreads GPU: ON (Vulkan)
  • gpu.available() / gpu.device_name() match a real GPU (e.g. vs vulkaninfo)
  • python -m pytest tests/unit/test_gpu_context.py -v -rs, passes; live tests skip or pass depending on hardware

Dynamic loader init, _ext.gpu bindings, cthreads.gpu API/errors, and
pytest coverage that skips when no GPU is available.
@K-T0BIAS K-T0BIAS self-assigned this Sep 5, 2026
@K-T0BIAS K-T0BIAS added the sub-feature Piece of a larger enchancement label Sep 5, 2026
@K-T0BIAS
K-T0BIAS merged commit 7e677a8 into 4-native-gpu-support-cthreads-for-vulkanspir-v Sep 5, 2026
2 checks passed
@K-T0BIAS
K-T0BIAS deleted the 9-gpu-01-vulkan-context-in-_ext branch September 5, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sub-feature Piece of a larger enchancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants